package com.example.menu;

import android.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.example.gamemenu.R;

public class SettingMenuFragment extends Fragment{
	private static final String TAG = "_SettingMenuFragment";
	public static final String KEY_SETTING_VIB = "vibrationCheck";
	
	View fragmentUi;
	Button btnCheckVib;
	
	SharedPreferences pref;
	
	boolean vibrationCheck;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
		vibrationCheck = pref.getBoolean(KEY_SETTING_VIB, false);

		fragmentUi = inflater.inflate(R.layout.fragment_menu_setting, container, false);
		btnCheckVib = (Button)fragmentUi.findViewById(R.id.btn_check_vib);
		
		if(!vibrationCheck){
			btnCheckVib.setBackgroundResource(R.drawable.check_box);
		} else{
			btnCheckVib.setBackgroundResource(R.drawable.check_box_checked);
		}
		
		
		btnCheckVib.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SharedPreferences.Editor editor = pref.edit();
				
				if(vibrationCheck){
					v.setBackgroundResource(R.drawable.check_box);
					vibrationCheck = false;
					Toast.makeText(getActivity(), "Vibration disabled", Toast.LENGTH_SHORT).show();
				} else{
					v.setBackgroundResource(R.drawable.check_box_checked);
					vibrationCheck = true;
					Toast.makeText(getActivity(), "Vibration enabled", Toast.LENGTH_SHORT).show();
				}
				editor.putBoolean(KEY_SETTING_VIB, vibrationCheck);
			}
		});
		
		return fragmentUi;
	}
	
}
